<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑功能域</title>
    <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css" />
    <style>
        .container { width: 86%; margin: 0 auto; }
        .form-group { margin-bottom: 15px; }
        .form-group label { display: block; margin-bottom: 5px; }
        .form-group input, .form-group select { width: 100%; padding: 8px; box-sizing: border-box; }
    </style>
</head>
<body>
    <div class="container">
        <form id="itemForm" class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">功能域名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" required lay-verify="required" class="layui-input" value="{{ item.name }}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">编号</label>
                <div class="layui-input-inline">
                    <input type="text" id="number" name="number" required lay-verify="required" class="layui-input" value="{{ item.number }}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-inline">
                    <input type="text" id="desc" name="desc" class="layui-input" value="{{ item.desc }}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">相关ECU</label>
                <div class="layui-input-inline">
                    <input type="text" id="ecu_list" name="ecu_list" class="layui-input" value="{{ item.ecu_list }}">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="itemForm">提交</button>
                </div>
            </div>
        </form>
    </div>

    <script src="../../static/admin/layui2.9.13/layui.js" type="text/javascript" charset="utf-8"></script>
    <script>
        layui.use(['form', 'layer'], function () {
            var form = layui.form;
            var layer = layui.layer;

            // 表单提交事件
            form.on('submit(itemForm)', function (data) {
                // 发送表单数据到后端
                fetch('/editItem', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(data.field)
                })
                .then(response => response.json())
                .then(data => {
                    layer.msg(data.msg);
                });

                return false; // 阻止表单默认提交行为
            });
        });
    </script>
</body>
</html>